home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / ai.prl / mike1.exe / FLU.KB < prev    next >
Encoding:
Text File  |  1990-07-12  |  6.0 KB  |  198 lines

  1. /* FLU.KB
  2. (See end of file for 'HOW TO RUN' info) 
  3.  
  4. Elementary (rule-based) medical diagnosis.  
  5. The purpose of this file is to get you used to
  6. the rule notation.  More sophisticated diagnosis
  7. would ordinarily use MIKE's frame system.
  8.  
  9. Example symptom descriptors might be as follows
  10.  
  11. Alice has a dry throat, a muzzy feeling in the head, a runny nose, sneezing
  12. and a slight transient fever, i.e. nothing worse than the common cold.  In
  13. MIKE list style syntax this would look like the following :
  14.  
  15. [alice, has, dry_throat]
  16. [alice, has, muzzy_feeling_head]
  17. [alice, has, runny_nose]
  18. [alice, is, sneezing]
  19. [alice, has, slight_transient_fever]
  20.  
  21. Bert has a blocked and runny nose, he is sneezing, and his eyes are red,
  22. itchey, and watering.  Bert is thus a hay-fever sufferer.  The MIKE for the
  23. following is listed below.
  24.  
  25. [bert, has, runny_nose]
  26. [bert, has, blocked_nose]
  27. [bert, is, sneezing]
  28. [bert, has, red_itchy_watery_eyes]
  29.  
  30. Another sufferer of the common cold in Charlie.  He has a dry throat, a
  31. muzzy feeling in the head, a runny nose and sneezing, and has a slight
  32. transient fever.  A MIKE version follows.
  33.  
  34. [charlie, has, dry_throat]
  35. [charlie, has, muzzy_feeling_head]
  36. [charlie, has, runny_nose]
  37. [charlie, is, sneezing]
  38. [charlie, has, slight_transient_fever]
  39.  
  40. Poor Donna's got laryngitis.  Her symptoms are a persistent dry cough, a
  41. hoarse voice, laryngeal discomfort, slight transient fever, and malaise.
  42. A MIKE version follows:-
  43.  
  44. [donna, has, persistent_dry_cough]
  45. [donna, has, hoarse_voice]
  46. [donna, has, laryngeal_discomfort]
  47. [donna, has, slight_transient_fever]
  48. [donna, has, malaise]
  49.  
  50. Eva has influenza.  She has a persistent dry cough, a sore throat, slight
  51. transient fever, shivering, malaise, a headache, and is suffering from diffuse
  52. aches and pains.
  53.  
  54. [eva, has, persistent_dry_cough]
  55. [eva, has, sore_throat]
  56. [eva, has, slight_transient_fever]
  57. [eva, is, shivering]
  58. [eva, has, malaise]
  59. [eva, has, headache]
  60. [eva, has, aches_and_pains]
  61.  
  62. Finally Frank has seasonal allergic rhinitis, better known as hay fever.
  63. He has a runny nose, a blocked nose, sneezing, and soar red eyes.
  64.  
  65. [frank, has, runny_nose]
  66. [frank, has, blocked_nose]
  67. [frank, is, sneezing]
  68. [frank, has, red_itchy_watery_eyes].
  69.  
  70. To 'seed' working memory with the above facts, you would need to use
  71. 'add'.  For example:
  72.  
  73.   ?- add [frank, has, runny_nose].
  74.   ?- add [frank, has, blocked_nose].
  75.  
  76. Alternatively, the appropriate facts could be added as part of the
  77. right-hand side of your very first rule, e.g.
  78.   rule init forward
  79.     if
  80.       start
  81.     then
  82.       add [frank, has, runny_nose] &
  83.       add [frank, has, blocked_nose] &
  84.       add [frank, is, sneezing] &
  85.       add [frank, has, red_itchy_watery_eyes].
  86.  
  87. We adopt the latter solution, as the following rule base shows:
  88. */
  89.  
  90.  
  91. /* ===============  diagnosis rule base ================== */
  92.  
  93. rule patient_initialisation_Rule forward
  94.  if
  95.    start   /* special symbol always in wm at first */
  96.  then
  97.   remove start &  /* get rid of special symbol */
  98.   add [alice, has, dry_throat] &
  99.   add [alice, has, muzzy_feeling_head] &
  100.   add [alice, has, runny_nose] &
  101.   add [alice, is, sneezing] &
  102.   add [alice, has, slight_transient_fever] &
  103.   add [bert, has, runny_nose] &
  104.   add [bert, has, blocked_nose] &
  105.   add [bert, is, sneezing] &
  106.   add [bert, has, red_itchy_watery_eyes] &
  107.   add [charlie, has, dry_throat] &
  108.   add [charlie, has, muzzy_feeling_head] &
  109.   add [charlie, has, runny_nose] &
  110.   add [charlie, is, sneezing] &
  111.   add [charlie, has, slight_transient_fever] &
  112.   add [donna, has, persistent_dry_cough] &
  113.   add [donna, has, hoarse_voice] &
  114.   add [donna, has, laryngeal_discomfort] &
  115.   add [donna, has, slight_transient_fever] &
  116.   add [donna, has, malaise] &
  117.   add [eva, has, persistent_dry_cough] &
  118.   add [eva, has, sore_throat] &
  119.   add [eva, has, slight_transient_fever] &
  120.   add [eva, is, shivering] &
  121.   add [eva, has, malaise] &
  122.   add [eva, has, headache] &
  123.   add [eva, has, aches_and_pains] &
  124.   add [frank, has, runny_nose] &
  125.   add [frank, has, blocked_nose] &
  126.   add [frank, is, sneezing] &
  127.   add [frank, has, red_itchy_watery_eyes] &
  128.   add diagnosing.
  129.  
  130.  
  131. rule 1 forward
  132.  if [Patient, has, runny_nose] &
  133.   [Patient, has, blocked_nose] &
  134.   [Patient, is, sneezing] &
  135.   [Patient, has, red_itchy_watery_eyes]
  136.  then
  137.   add [Patient, has, hay_fever] &   /* optional addition to working memory */
  138.   announce [Patient, ' has hay fever.'].
  139.  
  140. rule 2 forward
  141.  if [Patient, has, persistent_dry_cough] &
  142.   [Patient, has, hoarse_voice] &
  143.   [Patient, has, laryngeal_discomfort] &
  144.   [Patient, has, slight_transient_fever] &
  145.   [Patient, has, malaise]
  146.  then
  147.   add [Patient, has, laryngitis] &
  148.   announce [Patient, ' has laryngitis.'].
  149.  
  150. rule 3 forward
  151.  if [Patient, has, dry_throat] &
  152.   [Patient, has, muzzy_feeling_head] &
  153.   [Patient, has, runny_nose] &
  154.   [Patient, is, sneezing] &
  155.   [Patient, has, slight_transient_fever]
  156.  then
  157.   add [Patient, has, a, common_cold] &
  158.   announce [Patient, ' has a common cold.'].
  159.  
  160.  
  161. rule 4 forward
  162.  if [Patient, has, persistent_dry_cough] &
  163.   [Patient, has, sore_throat] &
  164.   [Patient, has, slight_transient_fever] &
  165.   [Patient, is, shivering] &
  166.   [Patient, has, malaise] &
  167.   [Patient, has, headache] &
  168.   [Patient, has, aches_and_pains]
  169.  then
  170.   add [Patient, has, influenza] &
  171.   announce [Patient, ' has influenza.'].
  172.  
  173. rule stop forward
  174.   if
  175.     diagnosing     /* least specific rule, so will fire last of all */
  176.   then
  177.     remove diagnosing &
  178.     announce [nl,'All possible diagnoses have been found',nl,
  179.                  'Diagnosis complete.  BYE! ',nl] &
  180.     halt.
  181.  
  182. /*   HOW TO RUN THIS EXAMPLE
  183. after loading the above rules, (using  ?- kb 'flu.kb'.)
  184. simply invoke the forward-chainer via
  185.    ?- fc.
  186.  
  187. The contents of working memory can be viewed at the end via
  188.    ?- show wm.
  189.  
  190. Dynamic viewing of working memory changes can be observed
  191. by toggling on tracing option number 5 as follows:
  192.    ?- tracing(5).
  193.  
  194. Finally, if you want to see how a conclusion was reached, use 'how',
  195. e.g.:
  196.    ?- how [frank, has, hay_fever].
  197. */
  198.